package com.zsrt.oa.recharge.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zsrt.oa.recharge.service.RechargeService;
import com.zsrt.oa.recharge.service.impl.RechargeServiceImpl;
import com.zsrt.utils.DBUtils;

/**
 * 充值记录的控制层
 * @author 罗智壕-13424431416
 *
 * 2017年6月8日
 */
public class RechargeController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	
	
	/**
	 * 初始化充值记录的服务层
	 */
	private RechargeService service = new RechargeServiceImpl();
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		String method = request.getParameter("method");
		
		if(null != method && !"".equals(method.trim())){
			HttpSession session = request.getSession();
			//初始化一个集合，到时候返回给前台
			Map<String, Object> map = new HashMap<String,Object>();
			if("rechargeAdd".equals(method)){
				String rechargeMoney = request.getParameter("rechargeMoney");
				
				//用户充值记录一条
				service.rechargeAdd(session.getAttribute("currentUser"), rechargeMoney, map);
			}else if("rechargeQuery".equals(method)){
				
				//查询用户充值多少钱
				service.rechargeQuery((String) session.getAttribute("currentUser"), map);
			}
			
			DBUtils.toJson(map, response);
		}
	}
}
